package Sort;

/**
 * @author fly
 * @create 2021--03--30--8:06
 */
public class InsertSort {

    public static void main(String[] args){
        int[] a=new int[]{4,3,2,1};
        helper(a);
        for(int x:a){
            System.out.println(x+" ");
        }
    }

    public static void helper(int[] a){
        int n=a.length;
        for(int i=1;i<n;i++){
            int cur=a[i];
            int j=i-1;
            while(j>=0&&a[j]>cur){
                a[j+1]=a[j];
                j--;
            }
            a[j+1]=cur;
        }
    }
}
